<script setup lang="ts">
import Login from "../components/Login.vue";
import {adminLogin} from "../apis/LoginApi.ts";
import router from "../router";
import {ElMessage} from "element-plus";
import {onMounted} from "vue";
import {useStore} from "../store";
import { dayjs } from 'element-plus'

const store = useStore();

const handler = async (accout:string, password:string) => {
  let studentRes = await adminLogin(accout, password);
  if (studentRes.flag){
    ElMessage({
      message: studentRes.msg,
      type: "success",
    })
    //将用户信息存储到pinia中
    store.adminIsLogin = true;
    //记录最近登录时间
    let time = dayjs().format('YYYY-MM-DD HH:mm:ss')
    store.adminInfo = studentRes.data;
    store.adminInfo.loginTime = time;
    console.log('store',store)
    await router.push("/admin");
  }else{
    ElMessage({
      message: studentRes.msg,
      type: "warning",
    })
  }
};

onMounted(async () => {

})
</script>

<template>
    <Login source="管理员" @handler="handler"/>
</template>

<style scoped>

</style>